<?php

namespace App\Service;

use App\Common\RedisCache;

class EnterpriseWeChat
{

    public function sendTextMsg($plat, $cropid, $secret, $extData)
    {
        $redisCacheObj = new RedisCache();
        $token = $redisCacheObj->getWxWorkAccessToken($cropid, $extData['agentid'], $secret);
        unset($redisCacheObj);
        $msgUrl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' . $token;
        $postData['touser'] = $extData['touser'];
        $postData['msgtype'] = 'text';
        $postData['agentid'] = $extData['agentid'];
        $postData['text']['content'] = $extData['content'].' ; 时间:'.date('Y-m-d H:i:s');
        $postData['safe'] = 0;
        $client = new \Yurun\Util\HttpRequest;
        $client->post($msgUrl,json_encode($postData),'json');
        unset($client, $postData, $token, $msgUrl, $plat, $cropid, $secret, $extData);
    }

    // public function send_url_msg($plat, $cropid, $secret, $extdata)
    // {
    //     $token = $this->getAccessToken($plat, $cropid, $secret);
    //     $posturl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' . $token;
    //     $postdata['touser'] = $extdata['touser'];
    //     $postdata['msgtype'] = 'textcard';
    //     $postdata['agentid'] = $extdata['agentid'];
    //     $postdata['textcard'] = $extdata['content'];
    //     \app\common\service\Common::httpRequest($posturl, json_encode($postdata));
    // }
}
